home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / misc / pclta-1.000 / pclta-1 / hostappl / display.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-18  |  6.0 KB  |  197 lines

  1. /*
  2.  * display.h,v 1.0 1996/03/18 14:18:33 miksic Exp
  3.  */
  4.  
  5. /* DISPLAY.H -- include file for Gizmo-2 seven segment display
  6.  * Copyright (c) 1993 by Echelon Corporation.
  7.  * All Rights Reserved.
  8.  */
  9.  
  10. // This NEURON C #include file contains code to drive the Motorola MC14489
  11. // seven-segment display controller chip, interfaced to the NEURON CHIP
  12. // using Neurowire output mode.
  13.  
  14. // Pin IO_8 is the Neurowire clock, pin IO_9 is the serial output data
  15. // Pin IO_2 is the chip select (may be modified).
  16.  
  17. // Change the following #defines if there are fewer than 4 digits
  18. // in the display.  The rightmost digit is numbered 0.
  19.  
  20. #define NUM_DIGITS     4
  21. #define MAX_NUMBER  9999
  22. #define MIN_NUMBER  -999
  23.  
  24. /////////////////////// DECLARATIONS ////////////////////////////////
  25.  
  26. IO_8 neurowire master select( IO_2 ) IO_seven_seg;
  27. IO_2 output bit IO_7_seg_select = 1;    // Initially unselected
  28.  
  29. unsigned char display_reg[ 3 ];        // 24 bits for 7-seg display reg
  30. unsigned char config_reg;              //  8 bits for 7-seg  config reg
  31.  
  32. unsigned char display_reg_copy[ 3 ];
  33. unsigned char config_reg_copy;
  34.  
  35.  
  36. //////////////////// CONTROL DISPLAY HARDWARE //////////////////////
  37.  
  38. void shift_out( void ) {        // update device hardware registers
  39.     memcpy( display_reg_copy, display_reg, 3 );
  40.     config_reg_copy = config_reg;
  41.     io_out( IO_seven_seg, &config_reg_copy, 8 );
  42.     io_out( IO_seven_seg, display_reg_copy, 24 );
  43. }
  44.  
  45. void clear_display( void ) {   // clear image of device registers
  46.     display_reg[ 0 ] = 0x80;   // max brightness
  47.     display_reg[ 1 ] = 0;      // blanks on all digits
  48.     display_reg[ 2 ] = 0;
  49.     config_reg = 0xFF;         // special decode on banks 1-5, normal mode
  50. }
  51.  
  52. ////////////////// SINGLE-CHARACTER DISPLAY FUNCTIONS //////////////
  53.  
  54. void display_decimal( int digit_number, int decimal ) {
  55.         // display decimal number ( 0 - 9 ) on a digit
  56.  
  57.     display_reg[ 2 - digit_number / 2 ] |=
  58.         ( digit_number & 1 ) ? ( decimal << 4 ) : decimal;
  59.     config_reg &= ~( 1 << ( digit_number + 1 ) );
  60. }
  61.  
  62. void display_char( int digit_number, int character, boolean is_numeric ) {
  63.           // display a character from the Gizmo character set
  64.  
  65.     display_reg[ 2 - digit_number / 2 ] |=
  66.         ( digit_number & 1 ) ? ( character << 4 ) : character;
  67.     if( is_numeric ) config_reg &= ~( 1 << ( digit_number + 1 ) );
  68. }
  69.  
  70. void display_DP( int digit_number ) {
  71.                                         // display decimal point on a digit
  72.     display_reg[ 0 ] |= ( digit_number + 1 ) << 4;
  73. }
  74.  
  75. void display_minus( int digit_number ) {
  76.                                         // display minus sign on a digit
  77.     display_reg[ 2 - digit_number / 2 ] |=
  78.         ( digit_number & 1 ) ? 0xD0 : 0x0D;
  79. }
  80.  
  81. //////////////////////// Blank the display /////////////////////////
  82.  
  83. void blank_display (void) {
  84.     clear_display();
  85.     shift_out();
  86. }
  87. ///////////////////////// DISPLAY DECIMAL NUMBER ///////////////////
  88.  
  89. void display_number( long number, int dp_digit );
  90.  
  91. #define NO_DP   -1      /* display number without  decimal point  */
  92. #define ALL_DPS -2      /* display number with all decimal points */
  93.  
  94. void display_number( long number, int dp_digit )
  95. {
  96.     int digit;
  97.     long local_num;
  98.  
  99.     clear_display( );       // clear image of display registers
  100.  
  101.     if( ( number > MAX_NUMBER ) || ( number < MIN_NUMBER ) ) {
  102.         display_reg[ 1 ] = display_reg[ 2 ] = 0xDD;
  103.         shift_out( );       // update hardware
  104.         return;             // display "----" for overrange
  105.     }
  106.     if( number < 0 ) {
  107.         display_minus( NUM_DIGITS - 1 );         // leading minus sign
  108.         local_num = - number;
  109.     } else local_num = number;
  110.  
  111.     for( digit = 0;
  112.                 local_num || ( digit <= max( dp_digit, 0 ) ); digit++ ) {
  113.                 // convert binary to decimal with leading zero suppress
  114.         if( ( number < 0 ) && ( digit == NUM_DIGITS - 1 ) ) break;
  115.         display_decimal( digit, ( int )( local_num % 10 ) );
  116.         local_num /= 10;
  117.     }
  118.     display_DP( dp_digit );  // display decimal point
  119.     shift_out( ) ;           // update hardware
  120. }
  121.  
  122. ///////////////////////////////////////////////////////////////
  123.  
  124. typedef struct {
  125.      unsigned character;
  126.      boolean  is_numeric;
  127.      char     ascii;
  128. } char_table_t;                 // Gizmo character set table
  129.  
  130. const char_table_t char_table[ ] = {
  131.     0xA, TRUE,      'A',
  132.     0xC, TRUE,      'C',
  133.     0xE, TRUE,      'E',
  134.     0xF, TRUE,      'F',
  135.     0x2, FALSE,     'H',
  136.     0x1, TRUE,      'I',
  137.     0x4, FALSE,     'J',
  138.     0x5, FALSE,     'L',
  139.     0x0, TRUE,      'O',
  140.     0x8, FALSE,     'P',
  141.     0x5, TRUE,      'S',
  142.     0xA, FALSE,     'U',
  143.     0xC, FALSE,     'Y',
  144.     0x2, TRUE,      'Z',
  145.     0xB, TRUE,      'b',
  146.     0x1, FALSE,     'c',
  147.     0xD, TRUE,      'd',
  148.     0x3, FALSE,     'h',
  149.     0x1, TRUE,      'l',
  150.     0x6, FALSE,     'n',
  151.     0x7, FALSE,     'o',
  152.     0x9, FALSE,     'r',
  153.     0xB, FALSE,     'u',
  154.     0xD, FALSE,     '-',
  155.     0xE, FALSE,     '=',
  156.     0xF, FALSE,     '%',     // degrees
  157.     0x0, FALSE,     ' ',
  158.     0x0, TRUE,      '0',
  159.     0x1, TRUE,      '1',
  160.     0x2, TRUE,      '2',
  161.     0x3, TRUE,      '3',
  162.     0x4, TRUE,      '4',
  163.     0x5, TRUE,      '5',
  164.     0x6, TRUE,      '6',
  165.     0x7, TRUE,      '7',
  166.     0x8, TRUE,      '8',
  167.     0x9, TRUE,      '9',
  168.     0xFF };
  169.  
  170. /////////////////////////// DISPLAY ASCII STRING //////////////////////
  171.  
  172. void display_string( const char * s, int dp_digit ) {
  173.     // displays first 4 characters of a string with optional decimal point
  174.  
  175.     const char_table_t * table_ptr;
  176.     int digit;
  177.  
  178.     clear_display( );          // all non-displayable chars show as blank
  179.  
  180.     for( digit = NUM_DIGITS - 1; digit >= 0; digit--, s++ ) {
  181.  
  182.         for( table_ptr = char_table; table_ptr->character != 0xFF;
  183.             table_ptr++ ) {
  184.  
  185.             if( * s == table_ptr->ascii ) {       // match char in table
  186.                 display_char( digit, table_ptr->character,
  187.                     table_ptr->is_numeric );
  188.                 break;
  189.             }
  190.         }
  191.     }
  192.     display_DP( dp_digit );  // display decimal point
  193.     shift_out( );            // update hardware
  194. }
  195.  
  196.  
  197.